package com.sise.service.impl;

import com.sise.config.rabbitmq.MqConstant;
import com.sise.service.RabbitMQMessageQueueService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 13680
 * Created by 13680 on 2018/8/17.
 */
@Service
public class MessageQueueServiceImpl implements RabbitMQMessageQueueService {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Override
    public void send(String queueName, String msg) {
        rabbitTemplate.convertAndSend(MqConstant.DEFAULT_EXCHANGE,queueName, msg);
    }

    @Override
    public void send(String queueName, String msg, long times) {
//        DlxMessage dlxMessage = new DlxMessage(queueName,msg,times);
//        MessagePostProcessor processor = new MessagePostProcessor(){
//            @Override
//            public Message postProcessMessage(Message message) throws AmqpException {
//                message.getMessageProperties().setExpiration(times + "");
//                return message;
//            }
//        };
//        dlxMessage.setExchange(MqConstant.DEFAULT_EXCHANGE);
//        log.info("queueName={}",queueName);
//        rabbitTemplate.convertAndSend(MqConstant.DEFAULT_EXCHANGE,MqConstant.DEFAULT_DEAD_LETTER_QUEUE_NAME, JsonUtils.toJson(dlxMessage), processor);
    }

}
